package com.hyzh.latte.vehicle.socket;

import com.coffee.socketio.CoffeeSocketio;
import com.coffee.socketio.CoffeeSocketioBuilder;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


/**
 * @author: songkui
 * @since: 2024/3/21 0:14
 */
@Component
@Order(2)
@Slf4j
@AllArgsConstructor
public class SocketStartInitialize implements ApplicationRunner {

    private final SocketConfigProperties socketConfigProperties;

    private final SocketConnectHandler connectHandler;

    private final SocketUserValidHandler userValidHandler;
    private final SocketCloseHandler closeHandler;

  /*  //Websocket
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }
    //Websocket
    @Bean
    public MochaWebSocketEndpoint mochaWebSocketEndpoint() {
        return new MochaWebSocketEndpoint();
    }*/

    @Override
    public void run(ApplicationArguments args) throws Exception {
        CoffeeSocketio.builder(CoffeeSocketioBuilder.builder()
                .socketCloseHandler(closeHandler)
                .socketConnectHandler(connectHandler)
                .socketUserValidHandler(userValidHandler)
                .initHandler(CommandType.getMap(), "com/hyzh/latte/vehicle/socket/handler"))
                .start(socketConfigProperties.getPort(), socketConfigProperties.getHost());

//        MochaWebSocket.start(MochaWSMetadataBuilder.builder()
//                .closeHandler(closeHandler)
//                .connectHandler(connectHandler)
//                .userValidHandler(userValidHandler)
//                .initHandler(HandlerCmdType.getMap(), "com/scshyzh/bss/ws/handler"));

    }


}
